package com.forward.uploadapp;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;

import com.forward.uploadapp.util.FileHelper;
import com.forward.uploadapp.util.NetUtils;
import com.forward.uploadapp.util.ToastUtils;

/**
 * Created by ljh on 17-12-15.
 */

public abstract class BaseActivity extends Activity {
    public static final int FROM_APP_INFO_ACTIVITY = 100;
    public static final int FROM_FILE_DISPLAY_ACTIVITY = 101;
    public static final int FROM_GET_JSON_ACTIVITY = 102;
    public static final int FROM_BMOB_ACTIVITY = 103;

    public static final int OUTPUT_ALL = 111;
    public static final int OUTPUT_GAME = 112;
    public static final int OUTPUT_HOME = 113;
    public static final int OUTPUT_SOFTWARE = 1114;

    private String mCurrentPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        initView();
        initData();
        initListener();
    }

    public String getCurrentPath() {
        if (TextUtils.isEmpty(mCurrentPath)) {
            mCurrentPath = FileHelper.BASE_PATH;
        }
        return mCurrentPath;
    }

    public void setCurrentPath(String currentPath) {
        mCurrentPath = currentPath;
    }

    public void downloadAllData() {
        new Thread() {
            @Override
            public void run() {
                String data = NetUtils.doGet("/all");
                if (!TextUtils.isEmpty(data)) {
                    final boolean b = FileHelper.writeFile(data, "/netData/all");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ToastUtils.toast(BaseActivity.this,
                                    getString(b ? R.string.download_success : R.string.download_fail));
                        }
                    });
                }
            }
        }.start();
    }

    public abstract int getLayoutId();

    public abstract void initView();

    public abstract void initData();

    public abstract void initListener();
}